package leetcode_题库;

import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Ding
 * @create 2022/8/19 9:12
 */
public class _283_移动零 {
    public static void main(String[] args) {
        int[] nums = new int[]{0,1,0,3,12};
        
        //记录当前检索到的0数量
        int cnt = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0){
                //如果第i个元素是0，就计数
                cnt++;
                continue;
            }
            if (cnt > 0){
                //否则，且计数大于0，就让当前元素和其前cnt位替换
                nums[i - cnt] = nums[i];
                nums[i] = 0;
            }
        }
        System.err.println(Arrays.toString(nums));

        /*

           > 2022/08/19 09:36:01
            解答成功:
                执行耗时:1 ms,击败了100.00% 的Java用户
                内存消耗:42.9 MB,击败了35.72% 的Java用户

         */
    }
}
